﻿namespace XUCore.WeChat.Enterprise.Net.ServerMessages.From
{
    using Newtonsoft.Json;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    using XUCore.WeChat.Net.ServerMessages.From;

    /// <summary>
    /// 通过获客链接申请好友事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionFriendRequestEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionFriendRequestEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionFriendRequestEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.friend_request;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }

        /// <summary>
        /// 点击的获客链接ID
        /// </summary>
        [XmlElement("LinkId")]
        public int LinkId { get; set; }

        /// <summary>
        /// 点击的获客链接配置的customer_channel值
        /// </summary>
        [XmlElement("State")]
        public int State { get; set; }
    }

    /// <summary>
    /// 删除获客链接事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionDeleteLinkEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionDeleteLinkEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionDeleteLinkEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.delete_link;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }

        /// <summary>
        /// 被删除的获客链接ID
        /// </summary>
        [XmlElement("LinkId")]
        public int LinkId { get; set; }
    }

    /// <summary>
    /// 微信客户发起会话事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionCustomerStartChatEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionCustomerStartChatEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionCustomerStartChatEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.customer_start_chat;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }

        /// <summary>
        /// 企业服务人员的UserID
        /// </summary>
        [XmlElement("UserID")]
        public int UserID { get; set; }

        /// <summary>
        /// 外部联系人的userid，注意不是企业成员的账号
        /// </summary>
        [XmlElement("ExternalUserID")]
        public int ExternalUserID { get; set; }
    }

    /// <summary>
    /// 获客链接不可用事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionLinkUnavailableEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionLinkUnavailableEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionLinkUnavailableEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.link_unavailable;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }

        /// <summary>
        /// 失效的获客链接ID
        /// </summary>
        [XmlElement("LinkId")]
        public int LinkId { get; set; }
    }

    /// <summary>
    /// 使用量已经耗尽事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionBalanceExhaustedEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionBalanceExhaustedEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionBalanceExhaustedEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.balance_exhausted;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }
    }

    /// <summary>
    /// 获客额度即将耗尽事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromCustomerAcquisitionBalanceLowEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromCustomerAcquisitionBalanceLowEvent"/> class.
        /// </summary>
        public FromCustomerAcquisitionBalanceLowEvent()
        {
            Event = FromEventTypes.customer_acquisition;
            ChangeType = CustomerAcquisitionChangeType.balance_low;
        }

        /// <summary>
        /// 操作类型
        /// </summary>
        public CustomerAcquisitionChangeType ChangeType { get; set; }
    }

    public enum CustomerAcquisitionChangeType
    {
        /// <summary>
        /// 获客额度即将耗尽事件
        /// </summary>
        balance_low = 1,
        /// <summary>
        /// 使用量已经耗尽事件
        /// </summary>
        balance_exhausted = 2,
        /// <summary>
        /// 获客链接不可用事件
        /// </summary>
        link_unavailable = 3,
        /// <summary>
        /// 微信客户发起会话事件
        /// </summary>
        customer_start_chat = 4,
        /// <summary>
        /// 删除获客链接事件
        /// </summary>
        delete_link = 5,
        /// <summary>
        /// 通过获客链接申请好友事件
        /// </summary>
        friend_request = 6,
    }
}
